<?php
// +----------------------------------------------------------------------
// |用户登录日志服务层
// +----------------------------------------------------------------------

namespace app\common\system;

use app\common\Mode\UserLog;
use app\common\Model\UserLogModel;
use app\common\Model\UserModel;
use app\common\system\SettingService;
use think\Request;
use app\common\service\utils\Utils;
use think\Config;

class UserLogService
{
/**
     * 用户日志添加
     *
     * @param array $param    日志数据
     * @param int   $log_type 日志类型：0登录，1操作，2退出
     * 
     * @return void
     */
    public static function add($param = [], $log_type = SettingService::LOG_TYPE_OPERATION)
    {
        // 用户日志记录是否开启
       // if (user_log_switch()) {
            if ($log_type == SettingService::LOG_TYPE_LOGIN) {
                $param['response_code'] = 200;
                $param['response_msg']  = '登录成功';
            }
            if (($param['response_msg'] ?? '') == '退出成功') {
                $log_type = SettingService::LOG_TYPE_LOGOUT;
            }   

            $ip_info    = Utils::ipInfo(); //获取ip
            $param['log_type']         = $log_type;
            $param['response_msg']       = $ip_info['ip'];             
            $model = new UserLogModel();
            $model->save($param);          
        }  
}